<!--页面主要内容-->
<main class="lyear-layout-content">
      
    <div class="container-fluid p-t-15">
      
      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-toolbar d-flex flex-column flex-md-row">
              <div class="toolbar-btn-action">
                <a class="btn btn-primary m-r-5 recoverys"><i class="mdi mdi-plus"></i> 恢复</a>
                <a class="btn btn-danger dels"><i class="mdi mdi-window-close"></i> 删除</a>
              </div>
              
              <form class="search-bar ml-md-auto" method="get" role="form">
                <input type="hidden" name="search_field" id="search-field" value="productname" />
                <div class="input-group ml-md-auto">
                  <div class="input-group-prepend">
                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="search-btn">商品名称</button>
                    <div class="dropdown-menu" style="">
                      <a class="dropdown-item" data-field="productname">商品名称</a>
                      <a class="dropdown-item" data-field="typename">分类名称</a>
                    </div>
                  </div>
                  <input type="text" class="form-control" name="keyword" placeholder="{$keyword}">
                </div>
              </form>
            </div>
            <div class="card-body">
              
              <div class="table-responsive">
                <table class="table table-bordered">
                  <thead>
                    <tr>
                      <th>
                        <div class="custom-control custom-checkbox">
                          <input type="checkbox" class="custom-control-input" id="check-all">
                          <label class="custom-control-label" for="check-all"></label>
                        </div>
                      </th>
                      <th>编号</th>
                      <th>商品名称</th>
                      <th>商品价格</th>
                      <th>库存</th>
                      <th>所属分类</th>
                      <th>状态</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    {foreach $ProductList as $item}
                      <tr>
                        <td>
                          <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input ids" name="ids[]" value="{$item.id}" id="ids-{$item.id}">
                            <label class="custom-control-label" for="ids-{$item.id}"></label>
                          </div>
                        </td>
                        <td>{++$num}</td>
                        <td>{$item.name}</td>
                        <td>{$item.price}</td>
                        <td>{$item.stock}</td>
                        <td>{$item.type.name}</td>
                        <td>{$item.flag_text}</td>
                        <td>
                          <div class="btn-group">
                            <!-- <a class="btn btn-xs btn-default" href="{:url('admin/product/edit',['proid' => $item.id])}" title="" data-toggle="tooltip" data-original-title="编辑"><i class="mdi mdi-pencil"></i></a> -->
                            <a class="btn btn-xs btn-default recovery" data-id="{$item.id}" data-toggle="tooltip" data-original-title="恢复"><i class="mdi mdi-file-eye"></i></a>
                            <a class="btn btn-xs btn-default del" data-id="{$item.id}" data-toggle="tooltip" data-original-title="删除"><i class="mdi mdi-window-close"></i></a>
                          </div>
                        </td>
                      </tr>
                    {/foreach}
                  </tbody>
                </table>
              </div>
              {$ProductList|raw}
     
            </div>
          </div>
        </div>
        
      </div>
      
    </div>
  
  </main>
  <!--End 页面主要内容-->
  <script>
    $(function () {
      $('.del').click(function () {
        $.confirm({
          title: '删除',
          content: '确认删除？无法恢复',
          buttons: {
            confirm: {
              text: '确认',
              btnClass: 'btn-info',
              action: () => {
                // 获取要删除的id
                let proid = $(this).data('id')

                $.ajax({
                  type: 'post',
                  url: `{:url('admin/product/del')}`,
                  data: {
                    proid,
                    action:'delete'
                  },
                  dataType: 'json',
                  success: (result) => {
                    if (result.code === 1) {
                      $.notify({
                        message: result.msg,
                      }, {
                        delay: 1000,
                        type: 'success',
                        onClose: function () {
                          location.reload();
                        }
                      })
                    } else {
                      $.notify({
                        message: result.msg,
                      }, {
                        delay: 1000,
                        type: 'warning'
                      })
                    }
                  }
                })


              }
            },
            cancel: {
              text: '取消',
              btnClass: 'btn-danger'
            }
          }
        })
      })


      $('.dels').click(function () {
        $.confirm({
          title: '批量删除',
          content: '确认批量删除？无法恢复',
          buttons: {
            confirm: {
              text: '确认',
              btnClass: 'btn-info',
              action: () => {
                // 获取要删除的id
                let proid = GetId()

                $.ajax({
                  type: 'post',
                  url: `{:url('admin/product/del')}`,
                  data: {
                    proid,
                    action:'delete'
                  },
                  dataType: 'json',
                  success: (result) => {
                    if (result.code === 1) {
                      $.notify({
                        message: result.msg,
                      }, {
                        delay: 1000,
                        type: 'success',
                        onClose: function () {
                          location.reload()
                        }
                      })
                    } else {
                      $.notify({
                        message: result.msg,
                      }, {
                        delay: 1000,
                        type: 'warning'
                      })
                    }
                  }
                })


              }
            },
            cancel: {
              text: '取消',
              btnClass: 'btn-danger'
            }
          }
        })

      })

      $('.recovery').click(function () {
            $.confirm({
                title: '恢复数据',
                content: '确认恢复数据？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let proid = $(this).data('id')

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/product/recovery')}`,
                                data: {
                                    proid
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })


                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })

        $('.recoverys').click(function () {
            $.confirm({
                title: '批量恢复数据',
                content: '确认批量恢复数据？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let proid = GetId()

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/product/recovery')}`,
                                data: {
                                    proid
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload()
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })


                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })

        })
    })
  </script>